Error: undefined method `contact' for nil:NilClass
Posted
by
user275801
on Stack Overflow
See other posts from Stack Overflow
or by user275801
Published on 2012-12-10T15:55:37Z
Indexed on
2012/12/10
17:03 UTC
Read the original article
Hit count: 186
I have a ruby/rails/hobo system that someone wrote a couple years ago, that I need to port to the latest version of ruby/rails/hobo. It seems that ruby doesn't care about backward compatibility, so code that used to work in the old app doesn't work anymore:
In the observation.rb model file, the old app has this:
belongs_to :survey
has_one :site, :through => :survey
def create_permitted?
acting_user == self.survey.contact or acting_user.administrator?
end
survey.rb model file has this:
belongs_to :contact, :class_name => 'User', :creator => true
Unfortunately the code in observation.rb doesn't work under the new ruby/rails/hobo, and it gives me the error:
NoMethodError in Observations#index
Showing controller: observations; dryml-tag: index-page where line #1 raised:
undefined method `contact' for nil:NilClass
Extracted source (around line #1):
0
Rails.root: /home/simon/ruby/frogwatch2
Application Trace | Framework Trace | Full Trace
app/models/observation.rb:48:in `create_permitted?'
How should the "create_permitted" method be changed? I'm finding that the documentation for ruby/rails/hobo is pretty atrocious (which is fair enough as it is free software). Also I don't even know how to begin searching for this on google (i've been trying for days).
Please help! :)
© Stack Overflow or respective owner